import { createSlice } from "@reduxjs/toolkit";

// 切片 
const userSlice = createSlice({
    name: 'user-slice',
    initialState: {//初始数据
        name: 'jojo',
        gender: '男',
        age: 18
    },
    reducers: {//操作数据的方法
        // 1、修改名称  
        setName(state, action) {//action.type action.payload  ，类似useReducer
                state.name = action.payload
        },
        // 2、修改性别
        setGender(state,action){
            state.gender = action.payload
        },
        // 2、修改年龄
        setAge(state,action){
            state.age = action.payload
        },
    }
})

export default userSlice